*****************************************************************************************************************************
**************** REPICATION DO-FILE FOR Andersson & Teorell, "The Double-Edged Sword", country-year data *************
*****************************************************************************************************************************

use "democratic transitions.dta", clear

* TABLE 2
eststo clear
set more off
* Model 1
logit e_boix_regime Lstate Llnmil Lgrowth Llnpop Llngdppc Llnoil Le_miinterc Le_miinteco Lregdem_year t t2 t3 Lntrans if l.e_boix_regime==0
preserve
  collapse e_boix_regime if e(sample),by(country_id)
  qui sum country_id
restore
scalar N_group=r(N)
eststo m1new
estadd scalar N_group = N_group
* Model 2
qui logit e_boix_regime Lstate l3nonviol Llnmil Lgrowth Llnpop Llngdppc Llnoil Le_miinterc Le_miinteco Lregdem_year t t2 t3 Lntrans if l.e_boix_regime==0
logit e_boix_regime Lstate           Llnmil Lgrowth Llnpop Llngdppc Llnoil Le_miinterc Le_miinteco Lregdem_year t t2 t3 Lntrans if e(sample)
preserve
  collapse e_boix_regime if e(sample),by(country_id)
  qui sum country_id
restore
scalar N_group=r(N)
eststo m2new
estadd scalar N_group = N_group
* Model 3
logit e_boix_regime Lstate l3nonviol Llnmil Lgrowth Llnpop Llngdppc Llnoil Le_miinterc Le_miinteco Lregdem_year t t2 t3 Lntrans if l.e_boix_regime==0
preserve
  collapse e_boix_regime if e(sample),by(country_id)
  qui sum country_id
restore
scalar N_group=r(N)
eststo m3new
estadd scalar N_group = N_group
* Model 4
logit dem_nonviol Lstate Llnmil Lgrowth Llnpop Llngdppc Llnoil Le_miinterc Le_miinteco Lregdem_year t t2 t3 Lntrans if l.e_boix_regime==0
preserve
  collapse e_boix_regime if e(sample),by(country_id)
  qui sum country_id
restore
scalar N_group=r(N)
eststo m4new
estadd scalar N_group = N_group
* Model 5
logit dem_rest Lstate Llnmil Lgrowth Llnpop Llngdppc Llnoil Le_miinterc Le_miinteco Lregdem_year t t2 t3 Lntrans if l.e_boix_regime==0
preserve
  collapse e_boix_regime if e(sample),by(country_id)
  qui sum country_id
restore
scalar N_group=r(N)
eststo m5new
estadd scalar N_group = N_group

esttab, b(3) se(3) star(* 0.10 ** 0.05 *** 0.01 ) sca("N" "N_group") sfmt(fmt %4.0fc) replace obslast label nogaps nodepvar keep(Lstate l3nonviol Llnmil  Lgrowth  Llnpop  Llngdppc  Llnoil  Le_miinterc  Le_miinteco t t2 t3 Lntrans Lregdem_year)  order(Lstate  l3nonviol Llnmil  Lgrowth  Llnpop  Llngdppc  Llnoil  Le_miinterc  Le_miinteco Lregdem_year t t2 t3 Lntrans) mtitles("\shortstack{All years\\}" "\shortstack{1900<\\}" "\shortstack{1900<\\}" "\shortstack{Preceding\\nonviolent}" "\shortstack{No preceding\\nonviolent}") nonote addnotes("Note: Logit coefficients with standard errors in parentheses." "* p<0.10, ** p<0.05, *** p<0.01")

* FIGURE 3
qui logit e_boix_regime Lstate Llnmil Lgrowth Llnpop Llngdppc Llnoil Le_miinterc Le_miinteco Lregdem_year t t2 t3 Lntrans if l.e_boix_regime==0
margins ,at(Lstate==(0(1)15))
label var state "State capacity"
gen pipe = "|"
gen rugplot=-0.01
marginsplot,  plot1opts(recast(line) lwidth(.8) lpattern(dash_dot)) ci1opts(recast(rline) xlabel(#5) lcolor(gs10) lpattern(dash_dot)) ytitle("p(transition to democracy)") xtitle ("State capacity (at t-1)") title("") scheme(lean2) addplot(scatter rugplot Lstate if e(sample), ms(none) ml(pipe)) leg(off) name(rug2)


* APPENDIX A. TABLE A2
eststo clear
qui logit e_boix_regime Lstate Llnmil Lgrowth Llnpop Llngdppc Llnoil Le_miinterc Le_miinteco Lregdem_year t t2 t3 l.ntrans if l.e_boix_regime==0
qui estpost sum e_boix_regime Lstate Llnmil Lgrowth Llnpop Llngdppc Llnoil Le_miinterc Le_miinteco Lregdem_year if e(sample)
esttab , replace nomtitles collabels("Mean" "Std.Dev." "Min" "Max" "Obs") cells("mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3)) count(fmt(0))") label nonumber noobs varwidth(40) 

* APPENDIX B. TABLE B2
eststo clear
set more off
qui xtpcse e_boix_regime Lstate Llnmil Lgrowth Llnpop Llngdppc Llnoil Le_miinterc Le_miinteco Lregdem_year t t2 t3 Lntrans if l.e_boix_regime==0, hetonly c(ar1)
eststo m1
qui xtpcse e_boix_regime Lstate Llnmil Lgrowth Llnpop Llngdppc Llnoil Le_miinterc Le_miinteco Lregdem_year Lntrans i.year i.country_id if l.e_boix_regime==0, hetonly c(ar1)
eststo m2
qui xtpcse e_boix_regime L5state L5lnmil L5growth L5lnpop L5lngdppc L5lnoil L5e_miinterc L5e_miinteco L5regdem_year L5ntrans t t2 t3  if l5.e_boix_regime==0, hetonly c(ar1)
eststo m3
qui xtpcse e_boix_regime L5state L5lnmil L5growth L5lnpop L5lngdppc L5lnoil L5e_miinterc L5e_miinteco L5regdem_year L5ntrans i.year i.country_id if l5.e_boix_regime==0, hetonly c(ar1)
eststo m4
esttab , b(3) se(3) star(* 0.10 ** 0.05 *** 0.01 ) sca("N" "N_g") sfmt(fmt %4.0fc) replace obslast label nogaps keep(Lstate L5state Llnmil L5lnmil Lgrowth L5growth Llnpop L5lnpop Llngdppc L5lngdppc Llnoil L5lnoil Le_miinterc L5e_miinterc Le_miinteco L5e_miinteco Lntrans L5ntrans Lregdem_year L5regdem_year)  order(Lstate L5state Llnmil L5lnmil Lgrowth L5growth Llnpop L5lnpop Llngdppc L5lngdppc Llnoil L5lnoil Le_miinterc L5e_miinterc Le_miinteco L5e_miinteco Lregdem_year L5regdem_year Lntrans L5ntrans) nomtitles nonote addnotes("Note: Regression coefficients with Prais-Winsten and heteroskedasticity-corrected" ///
                                                    "standard errors in parentheses. Cubic time polynomials present in models (1) and (3)," ///
													"country- and year-fixed effects present in models (2) and (4) (not displayed)." ///
													"* p<0.10, ** p<0.05, *** p<0.01")
* NOTE: To produce the table as it appears in the paper, the three rows with "YES" or "NO" have been inserted manually


* APPENDIX B. TABLE B3
gen Lv2x_polyarchy=l.v2x_polyarchy
label var Lv2x_polyarchy "Polyarchy at t-1"
gen L5v2x_polyarchy=l5.v2x_polyarchy
label var L5v2x_polyarchy "Polyarchy at t-5"
eststo clear
set more off
qui xtpcse v2x_polyarchy c.Lv2x_polyarchy##c.Lstate Llnmil Lgrowth Llnpop Llngdppc Llnoil Le_miinterc Le_miinteco Lregdem_year, hetonly c(ar1)
eststo m1
qui xtpcse v2x_polyarchy c.Lv2x_polyarchy##c.Lstate Llnmil Lgrowth Llnpop Llngdppc Llnoil Le_miinterc Le_miinteco Lregdem_year i.year i.country_id, hetonly c(ar1)
eststo m2
qui xtpcse v2x_polyarchy c.L5v2x_polyarchy##c.L5state L5lnmil L5growth L5lnpop L5lngdppc L5lnoil L5e_miinterc L5e_miinteco L5regdem_year, hetonly c(ar1)
eststo m3
qui xtpcse v2x_polyarchy c.L5v2x_polyarchy##c.L5state L5lnmil L5growth L5lnpop L5lngdppc L5lnoil L5e_miinterc L5e_miinteco L5regdem_year i.year i.country_id, hetonly c(ar1)
eststo m4
esttab , b(3) se(3) star(* 0.10 ** 0.05 *** 0.01 ) sca("N" "N_g") sfmt(fmt %4.0fc) replace obslast label nogaps keep(Lv2x_polyarchy L5v2x_polyarchy Lstate L5state c.Lv2x_polyarchy#c.Lstate c.L5v2x_polyarchy#c.L5state Llnmil L5lnmil Lgrowth L5growth Llnpop L5lnpop Llngdppc L5lngdppc Llnoil L5lnoil Le_miinterc L5e_miinterc Le_miinteco L5e_miinteco Lregdem_year L5regdem_year)  order(Lv2x_polyarchy L5v2x_polyarchy Lstate L5state c.Lv2x_polyarchy#c.Lstate c.L5v2x_polyarchy#c.L5state Llnmil L5lnmil Lgrowth L5growth Llnpop L5lnpop Llngdppc L5lngdppc Llnoil L5lnoil Le_miinterc L5e_miinterc Le_miinteco L5e_miinteco Lregdem_year L5regdem_year) nomtitles nonote addnotes("Note: Regression coefficients with Prais-Winsten and heteroskedasticity-corrected standard errors" "in parentheses." "* p<0.10, ** p<0.05, *** p<0.01") varwidth(40)
* NOTE: To produce the table as it appears in the paper, the two rows with "YES" or "NO" have been inserted manually


* APPENDIX B. FIGURE B1
qui xtpcse v2x_polyarchy c.Lv2x_polyarchy##c.Lstate Llnmil Lgrowth Llnpop Llngdppc Llnoil Le_miinterc Le_miinteco Lregdem_year i.year i.country_id, hetonly c(ar1)
margins, dydx(Lstate) at(Lv2x_polyarchy==(0(.1)1))
marginsplot,  plot1opts(recast(line) lwidth(.8) lpattern(dash_dot)) ci1opts(recast(rline) xlabel(#5) lcolor(gs10) lpattern(dash_dot)) ytitle("Effect of SC on polyarchy") xtitle ("Polyarchy at t-1") title("") scheme(lean2)

* APPENDIX B. FIGURE B2
qui xtpcse v2x_polyarchy c.L5v2x_polyarchy##c.L5state L5lnmil L5growth L5lnpop L5lngdppc L5lnoil L5e_miinterc L5e_miinteco L5regdem_year i.year i.country_id, hetonly c(ar1)
margins, dydx(L5state) at(L5v2x_polyarchy==(0(.1)1))
marginsplot,  plot1opts(recast(line) lwidth(.8) lpattern(dash_dot)) ci1opts(recast(rline) xlabel(#5) lcolor(gs10) lpattern(dash_dot)) ytitle("Effect of SC on polyarchy") xtitle ("Polyarchy at t-5") title("") scheme(lean2)






